"""
1、进入app内，点击用户故事
2、选择第一个用户故事
3、断言标题：油门一踩，梦想起步
"""
from appium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.common.touch_action import TouchAction
from time import sleep

cap = {}
cap['deviceName'] = "127.0.0.1:62001"       # 通过 adb devices -l 来获取
cap['appPackage'] = "com.lingyue.zebraloan"     # 通过 adb shell dumpsys activity activities
cap['appActivity'] = "com.lingyue.banana.activities.BananaLaunchActivity"
cap['platformName'] = "Android"
cap['platformVersion'] = "7.1.2"
# 初始化驱动
driver = webdriver.Remote("http://localhost:4723/wd/hub",cap)
# 设置隐式等待
driver.implicitly_wait(15)
# 点击同意按钮
WebDriverWait(driver,10,0.5).until(EC.presence_of_element_located((MobileBy.XPATH,"//*[@text='同意']"))).click()
"""
selenium中的xpath：//*[text()='登录']
                在selenium里面，根据文本定位是text()方法，返回文本值
appium中的xpath:   //*[@text='登录']
                在appium里面，是需要指定text值等于哪些，属于一个属性值，具体存在的
"""
# 等待页面加载
sleep(10)
# 点击用户故事
WebDriverWait(driver,10,0.5).until(EC.presence_of_all_elements_located((MobileBy.CLASS_NAME,"android.widget.ImageView")))[5].click()
# 等待页面加载
sleep(10)
# 通过x轴和y轴，点击第一个链接  227  440
TouchAction(driver).tap(x=227,y=440).perform()
"""
TouchAction:手势操作
tap：通过x轴和y轴点击
perform：执行这一组动作
"""
# 等待页面加载
sleep(3)
text = WebDriverWait(driver,10,0.5).until(EC.presence_of_element_located((MobileBy.XPATH,"//*[@text='油门一踩，梦想起步']"))).text
assert text == "油门一踩，梦想起步"

# 502  1495  560 376
# 滑动页面
sleep(3)
TouchAction(driver).press(x=502,y=1495).move_to(x=560,y=376).release().perform()
"""
press：从哪里开始滑动
move_to：滑动到哪里结束
release()：松开双手
perform：执行这一组动作
"""


sleep(10)



